home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / util / oid2lstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.7 KB  |  84 lines

  1. /* oid2lstr.c: oid to labeled string */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/util/RCS/oid2lstr.c,v 6.0 1991/12/18 20:25:18 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/util/RCS/oid2lstr.c,v 6.0 1991/12/18 20:25:18 jpo Rel $
  9.  *
  10.  * $Log: oid2lstr.c,v $
  11.  * Revision 6.0  1991/12/18  20:25:18  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "util.h"
  17. #include <isode/quipu/oid.h>
  18.  
  19. char    *oid2lstr(oid)
  20. OID    oid;
  21. {
  22.     static char    buf[BUFSIZ];
  23.     char    tmp[BUFSIZ];
  24.     char    *oidstr, *num, *ix, *label;
  25.     int    getLabel;
  26.  
  27.     num = oidstr = sprintoid(oid);
  28.  
  29.     if ('\0' == oidstr[0])
  30.         return NULLCP;
  31.  
  32.     buf[0] = '\0';
  33.     getLabel = TRUE;
  34.  
  35.     while (NULLCP != num) {
  36.         if ((ix = index(num, '.')) != NULLCP)
  37.             *ix = '\0';
  38.         if (TRUE == getLabel) {
  39.             if (num == oidstr) {
  40.                 /* first one put hack in */
  41.                 switch (atoi(num)) {
  42.                     case 0:
  43.                     (void) strcpy(tmp, "ccitt (0)");
  44.                     break;
  45.                     case 1:
  46.                     (void) strcpy(tmp, "iso (1)");
  47.                     break;
  48.                     case 2:
  49.                     (void) strcpy(tmp, "joint (2)");
  50.                     break;
  51.                     default:
  52.                     PP_LOG(LLOG_EXCEPTIONS,
  53.                            ("First element of OID not ccitt, iso or joint"));
  54.                     (void) sprintf(tmp, "(%d)", atoi(num));
  55.                     getLabel = FALSE;
  56.                 }
  57.             } else {
  58.                 OID    toid = oid_cpy(str2oid(oidstr));
  59.                 label = oid2name (toid, OIDPART);
  60.                 oid_free(toid);
  61.                 if (index(label, '.') != NULLCP) {
  62.                     getLabel = FALSE;
  63.                     (void) sprintf (tmp, "(%d)", atoi(num));
  64.                 } else 
  65.                     (void) sprintf(tmp, "%s (%d)",
  66.                         label,
  67.                         atoi(num));
  68.             }
  69.         } else
  70.             (void) sprintf (tmp, "(%d)", atoi(num));
  71.         if (ix != NULLCP) {
  72.             *ix = '.';
  73.             num = ix + 1;
  74.         } else
  75.             num = NULLCP;
  76.         if ('\0' != buf[0])
  77.             (void) strcat(buf, " ");
  78.         (void) strcat(buf, tmp);
  79.     }
  80.  
  81.     return buf;
  82. }
  83.     
  84.